home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / gg / ncurses-5.3.lha / ncurses-5.3 / c++ / cursesapp.cc next >
C/C++ Source or Header  |  2002-10-24  |  5KB  |  148 lines

  1. // * this is for making emacs happy: -*-Mode: C++;-*-
  2. /****************************************************************************
  3.  * Copyright (c) 1998,1999,2001 Free Software Foundation, Inc.              *
  4.  *                                                                          *
  5.  * Permission is hereby granted, free of charge, to any person obtaining a  *
  6.  * copy of this software and associated documentation files (the            *
  7.  * "Software"), to deal in the Software without restriction, including      *
  8.  * without limitation the rights to use, copy, modify, merge, publish,      *
  9.  * distribute, distribute with modifications, sublicense, and/or sell       *
  10.  * copies of the Software, and to permit persons to whom the Software is    *
  11.  * furnished to do so, subject to the following conditions:                 *
  12.  *                                                                          *
  13.  * The above copyright notice and this permission notice shall be included  *
  14.  * in all copies or substantial portions of the Software.                   *
  15.  *                                                                          *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
  17.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
  18.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
  19.  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
  20.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
  21.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
  22.  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
  23.  *                                                                          *
  24.  * Except as contained in this notice, the name(s) of the above copyright   *
  25.  * holders shall not be used in advertising or otherwise to promote the     *
  26.  * sale, use or other dealings in this Software without prior written       *
  27.  * authorization.                                                           *
  28.  ****************************************************************************/
  29.  
  30. /****************************************************************************
  31.  *   Author: Juergen Pfeifer, 1997                                          *
  32.  *   Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en             *
  33.  ****************************************************************************/
  34.  
  35. #include "internal.h"
  36. #include "cursesapp.h"
  37.  
  38. MODULE_ID("$Id: cursesapp.cc,v 1.9 2002/07/06 15:47:52 juergen Exp $")
  39.  
  40. void
  41. NCursesApplication::init(bool bColors) {
  42.   if (bColors)
  43.     NCursesWindow::useColors();
  44.   
  45.   if (Root_Window->colors() > 1) {    
  46.     b_Colors = TRUE;
  47.     Root_Window->setcolor(1);
  48.     Root_Window->setpalette(COLOR_YELLOW,COLOR_BLUE);
  49.     Root_Window->setcolor(2);
  50.     Root_Window->setpalette(COLOR_CYAN,COLOR_BLUE);
  51.     Root_Window->setcolor(3);
  52.     Root_Window->setpalette(COLOR_BLACK,COLOR_BLUE);
  53.     Root_Window->setcolor(4);
  54.     Root_Window->setpalette(COLOR_BLACK,COLOR_CYAN);
  55.     Root_Window->setcolor(5);
  56.     Root_Window->setpalette(COLOR_BLUE,COLOR_YELLOW);
  57.     Root_Window->setcolor(6);
  58.     Root_Window->setpalette(COLOR_BLACK,COLOR_GREEN);
  59.   }
  60.   else
  61.     b_Colors = FALSE;
  62.  
  63.   Root_Window->bkgd(' '|window_backgrounds());
  64. }
  65.  
  66. NCursesApplication* NCursesApplication::theApp = 0;
  67. NCursesWindow* NCursesApplication::titleWindow = 0;
  68. NCursesApplication::SLK_Link* NCursesApplication::slk_stack = 0;
  69.  
  70. NCursesApplication::~NCursesApplication() {
  71.   Soft_Label_Key_Set* S;
  72.  
  73.   delete titleWindow;
  74.   while( (S=top()) ) {
  75.     pop();
  76.     delete S;
  77.   }
  78.   delete Root_Window;
  79.   ::endwin();
  80. }
  81.  
  82. int NCursesApplication::rinit(NCursesWindow& w) {
  83.   titleWindow = &w;
  84.   return OK;
  85. }
  86.  
  87. void NCursesApplication::push(Soft_Label_Key_Set& S) {
  88.   SLK_Link* L = new SLK_Link;
  89.   assert(L != 0);
  90.   L->prev = slk_stack;
  91.   L->SLKs = &S;
  92.   slk_stack = L;
  93.   if (Root_Window)
  94.     S.show();
  95. }
  96.  
  97. bool NCursesApplication::pop() {
  98.   if (slk_stack) {
  99.     SLK_Link* L = slk_stack;
  100.     slk_stack = slk_stack->prev;
  101.     delete L;
  102.     if (Root_Window && top())
  103.       top()->show();
  104.   }
  105.   return (slk_stack ? FALSE : TRUE);
  106. }
  107.  
  108. Soft_Label_Key_Set* NCursesApplication::top() const {
  109.   if (slk_stack)
  110.     return slk_stack->SLKs;
  111.   else
  112.     return (Soft_Label_Key_Set*)0;
  113. }
  114.  
  115. int NCursesApplication::operator()(void) {
  116.   bool bColors = b_Colors;
  117.   Soft_Label_Key_Set* S;
  118.  
  119.   int ts = titlesize();
  120.   if (ts>0)
  121.     NCursesWindow::ripoffline(ts,rinit);
  122.   Soft_Label_Key_Set::Label_Layout fmt = useSLKs();
  123.   if (fmt!=Soft_Label_Key_Set::None) {    
  124.     S = new Soft_Label_Key_Set(fmt);
  125.     assert(S != 0);
  126.     init_labels(*S);
  127.   }
  128.  
  129.   Root_Window = new NCursesWindow(::stdscr);
  130.   init(bColors);
  131.  
  132.   if (ts>0)
  133.     title();
  134.   if (fmt!=Soft_Label_Key_Set::None) {
  135.     push(*S);
  136.   }
  137.  
  138.   return run();
  139. }
  140.  
  141. NCursesApplication::NCursesApplication(bool bColors) {
  142.   b_Colors = bColors;
  143.   if (theApp)
  144.     THROW(new NCursesException("Application object already created."));
  145.   else
  146.     theApp = this;
  147. }
  148.